package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	
	/**
	 * ...
	 * @author Lorenzo Nuvoletta
	 */
	public class Main extends Sprite 
	{
		private var bmpd:BitmapData;
		private var actor:Actor;
		private var actors:Vector.<Actor> = new Vector.<Actor>();
		private var matrix:Matrix = new Matrix();
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			bmpd = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xffffff);
			var bmp:Bitmap = new Bitmap(bmpd);
			addChild(bmp);
			
			setActors();
		}
		
		private function setActors():void 
		{
			actors.push( new Actor(stage.stageWidth, stage.stageHeight, Actor.SIN_CIRCLES) );	
			actors.push( new Actor(stage.stageWidth, stage.stageHeight, Actor.STRAIGHT_CIRCLES) );	
			this.addEventListener(Event.ENTER_FRAME, update);
		}
		
		private function update(e:Event):void 
		{	
			for (var i:int = 0; i < actors.length; i++){
				actors[i].update();
				matrix.identity();
				matrix.translate(actors[i].x, actors[i].y);
				bmpd.draw(actors[i], matrix);
			}
		}
		
	}
	
}